// JavaScript Document
(function(){
	//星星打分控件-星星个数
	var startLength = 5;
	//星星打分控件-星星title
	var aTitle = ['很差', '一般', '好', '很好', '非常好' ];
	
	/*
	 *单个星星评分调用
	 *针对单个使用星星评分调用
	 *name表单name
	 *return undefined	
	*/
	window.myStart = function(name){
		var aStart = [];
		var oInput = document.getElementsByName(name)[0];
		//div
		var oDiv = document.createElement("div");
		oDiv.className = "subgroup_start";
		oInput.parentNode.insertBefore(oDiv, oInput);
		//ul
		var oUl = document.createElement("ul");
		oUl.onmouseout = function(){
			for(var i=0;i<aStart.length;i++)
			{
				if (i <= oInput.value-1){
					aStart[i].className='active';
				} else {
					aStart[i].className='';
				}
			}
		}
		oDiv.appendChild(oUl);
		//li
		for(var i=0;i<startLength;i++)
		{
			var oLi = document.createElement("li");
			var oA = document.createElement("a");
			oA.href = "javascript:;";
			oA.title = aTitle[i];
			oA.index = i;
			if (oA.index < oInput.value)
			{
				oA.className='active';
			}
			oA.onmouseover = function(){
				for(var i=0;i<aStart.length;i++)
				{
					if (this.index >= i) {
						aStart[i].className='active';
					} else {
						aStart[i].className='';
					}
				}
			}
			oA.onclick = function(){
				oInput.value = this.index + 1;
			}
			oLi.appendChild(oA);
			oUl.appendChild(oLi);
			aStart.push(oA);
		}
		
		oInput.style.display = "none";
	}
	
	/*
	 *星星打分控件
	 *针对整个页面全部需要使用打分控件
	 *return undefined	
	*/
	window.myStartAll = function(){
		var aInput = document.getElementsByTagName("input");
		var subgroup_starts = [];
		for (var i=0; i<aInput.length; i++)
		{
			if (aInput[i].getAttribute('date-type') == 'subgroup_start') {
				subgroup_starts.push(aInput[i]);
			}
		}
		for (var i=0; i<subgroup_starts.length; i++)
		{
			myStart(subgroup_starts[i].name);
		}
	}
	
	/*
	 *星星打分控件css引用
	*/
	var oLink = document.createElement("link");
	oLink.href = "start.css";
	oLink.type = "text/css";
	oLink.rel = "stylesheet"
	document.getElementsByTagName("head")[0].appendChild(oLink);	
})();